﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Utility;
using Runda.EShop.Bll;
using Runda.EShop.Common.Entity;

namespace Runda.EShop.SaaS.SysManage
{
    public partial class NoticeList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid(ConstHelper.PAGE_INIT_INDEX);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load +=new EventHandler(Page_Load);
            this.AspNetPager1.PageChanged += new EventHandler(AspNetPager1_PageChanged);
            btnQuery.Click += new EventHandler(btnQuery_Click);
        }

        void btnQuery_Click(object sender, EventArgs e)
        {
            BindGrid(ConstHelper.PAGE_INIT_INDEX);
        }

        void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }

        private void BindGrid(int PageIndex)
        {
            SystemBll bll = new SystemBll();
            List<SqlDbParameter> parms = new List<SqlDbParameter>();

            int RecordCount = 0;
            List<SysNoticeEntity> list = bll.GetAll<SysNoticeEntity>(parms, "CreatedAt desc", AspNetPager1.PageSize, PageIndex, out RecordCount);
            gvNoticeList.DataSource = list;
            gvNoticeList.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void gvNoticeList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Guid NoticeID = new Guid(gvNoticeList.DataKeys[e.RowIndex]["NoticeID"].ToString()); 
            SystemBll bll = new SystemBll();
            bll.LogicDelete<SysNoticeEntity>(" and NoticeID='"+NoticeID+"'");
            BindGrid(ConstHelper.PAGE_INIT_INDEX);

            DoOperationLog(EnumHelper.OperationType.Delete, "删除公告，ID:" + NoticeID);
        }

    }
}